<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>OA后台管理</title>
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="shortcut icon" href="../../static/favicon.ico">
{#    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />#}
    <link rel="stylesheet" href="../../static/back_management/css/font.css">
	<link rel="stylesheet" href="../../static/back_management/css/xadmin.css">
    <script type="text/javascript" src="../../static/back_management/js/jquery.min.js"></script>
{#    <script src="../../static/back_management/lib/layui/layui.js" charset="utf-8"></script>#}
{#    <script type="text/javascript" src="../../static/back_management/js/xadmin.js"></script>#}

</head>
<body class="login-bg">
    
    <div class="login">
        <div class="message">管理员登录</div>
        <div id="darkbannerwrap"></div>
        
        <div>
            <input name="username" placeholder="用户名" id="username" type="text">
            <hr class="hr15">
            <input name="password" placeholder="密码" id="pwd" type="password">
            <hr class="hr15">
            <div style="width: 100%;">
                <input name="validate" id="validate" placeholder="验证码" type="text" style="width: 65%;">
                <button id="get_validate" onclick="ObtainVerificationCode()" style="display: inline-block;border: #189F92 solid 1px;background: #189F92;color: white;border-radius: 3px;margin-left: 10px;height: 49px;width: 105px;cursor: pointer;">获取验证码</button>
            </div>
            <hr class="hr15">
            <input value="登录" id="submmit_but" style="width:100%;" type="submit" onclick="signin()">
            <hr class="hr20" >
            <div class="be-con" style="width: 100%;text-align: right;padding-right: 15px;cursor: pointer;padding-top: 20px;">
                <a href="/personal-center/signin" style="letter-spacing:1px;font-size: 14px;">登录用户端</a>
            </div>
        </div>
    </div>

    <script>
        function signin() {
            var form = new FormData();
            var username = document.getElementById("username").value;
            var pwd = document.getElementById("pwd").value;
            var validate = document.getElementById("validate").value;
            if (!validate) {
                alert("请输入验证码！")
                return false
            }
            form.append("username", username);
            form.append("pwd", pwd);
            form.append("platform", "web")
            form.append("validate", validate)
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/personal-center/signin", true);
            xhr.send(form);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        var JsonData = JSON.parse(xhr.responseText);
                        if(JsonData['code'] === 200){
                            location.href = "/back-management/index.html";
                        }
                        else{
                            alert(JsonData['message'])
                    }

                    }
                }
            };
        }

        $('#username').bind('keydown', function (event) {
            var event = window.event || arguments.callee.caller.arguments[0];
            if (event.keyCode === 13) {
                signin();
            }
        });

        $('#pwd').bind('keydown', function (event) {
            var event = window.event || arguments.callee.caller.arguments[0];
            if (event.keyCode === 13) {
                signin();
            }
        });

        $('#submmit_but').bind('keydown', function (event) {
            var event = window.event || arguments.callee.caller.arguments[0];
            if (event.keyCode === 13) {
                signin();
            }
        });

        var count = 59; //间隔函数，1秒执行
        var timer; //timer变量，控制时间
        var curCount;//当前剩余秒数
        function ObtainVerificationCode() {
            var username = document.getElementById("username").value;
            if (!username) {
                alert("未输入登陆账号，无法获取验证码！")
                return false
            }
            ApplyCode(username);
        }
        
        function ApplyCode(username) {
            var xhr = new XMLHttpRequest();
            var form = new FormData();
            form.append('username', username)
            xhr.open('post', "/back-management/apply_code", true);
            xhr.send(form);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        var JsonData = JSON.parse(xhr.responseText);
                        if (JsonData['code'] === 400) {
                            alert(JsonData['message'])
                            return false
                        }
                        document.getElementById("get_validate").removeAttribute("onclick");
                        curCount = count;
                        document.getElementById('get_validate').innerText = '60秒再获取';
                        timer = window.setInterval(SetRemainTime, 1000); //启动计时器，1秒执行一次
                    }
                }
            };
        }

        function SetRemainTime() {
            if (curCount === 1) {
                window.clearInterval(timer);//停止计时器
                document.getElementById("get_validate").setAttribute("onclick", "ObtainVerificationCode()");
                document.getElementById('get_validate').innerText = '重新发送';
            }
            else {
                curCount--;
                document.getElementById('get_validate').innerText = curCount + "秒再获取";
            }
        }
    </script>

    
    <!-- 底部结束 -->
    
</body>
</html>